//
//  PictureTestTableViewCell.m
//  AndCampus
//
//  Created by 史宵宵 on 2018/3/30.
//  Copyright © 2018年 史宵宵. All rights reserved.
//

#import "PictureTestTableViewCell.h"
@interface PictureTestTableViewCell()
@property (nonatomic,weak) UIButton *selectButton;
@end

@implementation PictureTestTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
- (void)setPictureTestInfo:(PictureTestModel *)pictureTestInfo{
    _pictureTestInfo = pictureTestInfo;
    self.titleLabel.text = [NSString stringWithFormat:@"%ld/%ld %@",(long)self.num,(long)self.total,pictureTestInfo.title];
    [self.subjectImage sd_setImageWithURL:[NSURL URLWithString:pictureTestInfo.titleImg] placeholderImage: KLIVECLASSDEFAULT];
    if ([pictureTestInfo.answer isEqualToString:@"A"]) {
        self.aButton.selected = YES;
        self.bButton.selected = NO;
        self.cButton.selected = NO;
        self.dButton.selected = NO;
        self.selectButton = self.aButton;
    }else if ([pictureTestInfo.answer isEqualToString:@"B"]) {
        self.aButton.selected = NO;
        self.bButton.selected = YES;
        self.cButton.selected = NO;
        self.dButton.selected = NO;
        self.selectButton = self.bButton;
    }else if ([pictureTestInfo.answer isEqualToString:@"C"]) {
        self.aButton.selected = NO;
        self.bButton.selected = NO;
        self.cButton.selected = YES;
        self.dButton.selected = NO;
        self.selectButton = self.cButton;
    }else if ([pictureTestInfo.answer isEqualToString:@"D"]) {
        self.aButton.selected = NO;
        self.bButton.selected = NO;
        self.cButton.selected = NO;
        self.dButton.selected = YES;
        self.selectButton = self.dButton;
    }else{
        self.aButton.selected = NO;
        self.bButton.selected = NO;
        self.cButton.selected = NO;
        self.dButton.selected = NO;
        self.selectButton.selected = NO;
    }
    if ([pictureTestInfo.isImg isEqualToString:@"1"]) {
        [self.aAnswerImage sd_setImageWithURL:[NSURL URLWithString:pictureTestInfo.answerA] placeholderImage: KLIVECLASSDEFAULT];
        [self.bAnswerImage sd_setImageWithURL:[NSURL URLWithString:pictureTestInfo.answerB] placeholderImage: KLIVECLASSDEFAULT];
        [self.cAnswerImage sd_setImageWithURL:[NSURL URLWithString:pictureTestInfo.answerC] placeholderImage: KLIVECLASSDEFAULT];
        [self.dAnswerImage sd_setImageWithURL:[NSURL URLWithString:pictureTestInfo.answerD] placeholderImage: KLIVECLASSDEFAULT];
    }else{
        [self.aButton setTitle:[NSString stringWithFormat:@" %@",pictureTestInfo.answerA] forState:UIControlStateNormal];
        [self.bButton setTitle:[NSString stringWithFormat:@" %@",pictureTestInfo.answerB] forState:UIControlStateNormal];
        [self.cButton setTitle:[NSString stringWithFormat:@" %@",pictureTestInfo.answerC] forState:UIControlStateNormal];
        [self.dButton setTitle:[NSString stringWithFormat:@" %@",pictureTestInfo.answerD] forState:UIControlStateNormal];
        [self.aButton setTitleColor:KTEXTMAINCOLOR forState:UIControlStateNormal];
        [self.bButton setTitleColor:KTEXTMAINCOLOR forState:UIControlStateNormal];
        [self.cButton setTitleColor:KTEXTMAINCOLOR forState:UIControlStateNormal];
        [self.dButton setTitleColor:KTEXTMAINCOLOR forState:UIControlStateNormal];
        self.aAnswerImage.hidden = YES;
        self.bAnswerImage.hidden = YES;
        self.cAnswerImage.hidden = YES;
        self.dAnswerImage.hidden = YES;
    }
    
}
- (IBAction)aSelect:(id)sender {
    UIButton *button = (UIButton *)sender;
    self.selectButton.selected = NO;
    button.selected = YES;
    self.selectButton = button;
    if (self.selectPictureTestBlock) {
        self.selectPictureTestBlock(@"A");
    }
}
- (IBAction)bSelect:(id)sender {
    UIButton *button = (UIButton *)sender;
    self.selectButton.selected = NO;
    button.selected = YES;
    self.selectButton = button;
    if (self.selectPictureTestBlock) {
        self.selectPictureTestBlock(@"B");
    }
}
- (IBAction)cSelect:(id)sender {
    UIButton *button = (UIButton *)sender;
    self.selectButton.selected = NO;
    button.selected = YES;
    self.selectButton = button;
    if (self.selectPictureTestBlock) {
        self.selectPictureTestBlock(@"C");
    }
}
- (IBAction)dSelect:(id)sender {
    UIButton *button = (UIButton *)sender;
    self.selectButton.selected = NO;
    button.selected = YES;
    self.selectButton = button;
    if (self.selectPictureTestBlock) {
        self.selectPictureTestBlock(@"D");
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
